<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            首页
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('m:anage/index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="{:U('vendor/index')}"><i class="fa fa-dashboard"></i> 供应商档案</a></li>
            <li class="active">货品关联</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="tab-content">
            <div class="tab-pane active" id="tab_0">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">{$info.vendor_name}</h3>
                        <div class="form-inline pull-right">
                            <form action="" method="get" pjax-container="">
                                <fieldset>
                                    <select class="form-control" name="search_field" style="height: 30px; font-size: 12px;">
                                        <option value="name" <if condition="$search_field eq 'name'">selected="selected"</if>>货品名称</option>
                                        <option value="barcode" <if condition="$search_field eq 'barcode'">selected="selected"</if>>条码</option>
                                        <option value="bn" <if condition="$search_field eq 'bn'">selected="selected"</if>>BN</option>
                                    </select>
                                    <div class="input-group input-group-sm">
                                        <div class="input-group input-group-sm">
                                            <input type="text" class="form-control" placeholder="" name="search" value="{$search}">
                                        </div>
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>

                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th><input type="checkbox" class="grid-select-all"></th>
                                <th>货品ID<a class="fa fa-fw fa-sort" href=""></a></th>
                                <th>商品ID</th>
                                <th>名称</th>
                                <th>图片</th>
                                <th>条码</th>
                                <th>BN</th>
                                <th>销售价</th>
                                <th>折扣价</th>
                                <th>供应价格</th>
                                <th>供应数量</th>
                                <!--<th>Action</th>-->
                            </tr>
                            <volist name="list" id="vo">
                                <tr>
                                    <td><input type="checkbox" class="grid-item" data-id="{$vo.pid}" <if condition="$vo.vgood_id neq ''">checked="checked"</if> ></td>
                                    <td>{$vo.pid}</td>
                                    <td>{$vo.gid}</td>
                                    <td>{$vo.name}</td>
                                    <td><img src="{$vo.gid|getThumb=###}" alt=""></td>
                                    <td>{$vo.barcode}</td>
                                    <td>{$vo.bn}</td>
                                    <td>{$vo.price}</td>
                                    <td>{$vo.cost}</td>
                                    <td><input type="text" vgoodid="{$vo.vgood_id}" class="form-control" name="vendor_price" value="{$vo.vendor_price|default=$vo['cost']}"></td>
                                    <td><input type="text" vendorid="{$vo.vendor_id}" class="form-control" name="vendor_sum" value="{$vo.vendor_sum|default='1000'}"></td>
                                    <!--<td>
                                        <a href="{:U('manage/vendor/edit', array('vendor_id'=>$vo['vendor_id']), '')}"><i class="fa fa-edit"></i></a>
                                        <a href="javascript:void(0);" data-id="{$vo.vendor_id}" class="_delete"><i class="fa fa-trash"></i></a>
                                        <a href="{:U('manage/vendor/products', array('vendor_id'=>$vo['vendor_id']), '')}"><i class="fa fa-edit"></i></a>
                                    </td>-->
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-sm btn-info batch-delete">保存</a>

                        <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                        {$page}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>

        </div>
    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer"/>
<script data-exec-on-popstate>

    $(function () {

        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click',function(e){
            var data = [];
            $(".grid-item").each(function (i) {
                if ($(this)[0].checked) {
                    var is_show = true;
                } else {
                    var is_show = false;
                }
                var product_id = $(this).parent().parent().find('td:eq(1)').text();
                var goods_id = $(this).parent().parent().find('td:eq(2)').text();
                var vendor_price = $(this).parent().parent().find('input[name=vendor_price]').val();
                var vendor_sum = $(this).parent().parent().find('input[name=vendor_sum]').val();

                data.push({product_id:product_id, goods_id:goods_id, vendor_price:vendor_price, vendor_sum:vendor_sum, is_show:is_show});
            });
            console.log(data);
            if (data) {
                $.ajax({
                    type: "POST",
                    url: "{:U('vendor/save_edit', array('vendor_id'=> $info['vendor_id']), '')}",
                    data: {data:data},
                    success: function(msg){
                        if (msg.status) {
                            alert(msg.message);
                        } else {
                            alert(msg.message)
                        }
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        })

    });
</script>